#ifndef BACOCARE_H
#define BACOCARE_H

#include <QObject>
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDir>
#include <QSharedPointer>
#include "trackitem.h"
#include "detalheitem.h"

class BancoCare : public QObject
{
    Q_OBJECT
public:
    explicit BancoCare(QObject *parent = 0);
    ~BancoCare();

    Q_INVOKABLE void CarregarTracks();
    Q_INVOKABLE void CarregarDetalheTrack(int idTrack);
    Q_INVOKABLE void CarregarDetalheTrack(const QString &trackNumber);    
    Q_INVOKABLE bool TrackExiste(const QString &trackNumber);

private:
    QSqlDatabase _db;
    int _lastIdTrack;

    void PrepararDatabase();

    int AdicionarTrack(const QString &trackNumber);
    int BuscarTrack(const QString &trackNumber);
    int AdicionarNovoDetalhe(int idTrack, const QDateTime data, const QString &descricao, const QString &status);
    int BuscarDetalhe(int idTrack, const QDateTime data);
    int AdicionarNovoComplemento(int idDetalhe, const QString &descricao);

    void DispararSignalTrackAdd(int idTrack, const QString &trackNumber, const QString &trackDescription);
    void DispararSignalDetalheAdd(DetalheItem* item);
    void DispararSignalComplementoAdd(int idTrack, int idDetalhe, ComplementoDetalheItem *item);

signals:
    void trackAdd(TrackItem* item);
    void detalheAdd(DetalheItem *item);
    void complementoAdd(int idTrack, int idDetalhe, ComplementoDetalheItem* item);
    void trackRemove(int id);
    void limparDetalhes();
    void fimProcessamento(int idTrack);
    void trackInvalido();

public slots:
    void avaliar(const QString &trackNumber, QList<DetalheItem*> itens);
    void removerTrack(int idTrack);
    void atualizarTrack(int idTrack, const QString &description);
    
};

#endif // BACOCARE_H
